{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2b394e21",
   "metadata": {},
   "source": [
    "# 数据获取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "922caf0c",
   "metadata": {},
   "outputs": [],
   "source": [
    "url ='https://api-c.liepin.com/api/com.liepin.searchfront4c.pc-search-job'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4489523a",
   "metadata": {},
   "source": [
    "* 请求方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "a41d3fcc",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "8e9c4ce4",
   "metadata": {},
   "outputs": [],
   "source": [
    "paload={\"data\":{\n",
    "  \"city\": \"050020\",\n",
    "  \"dq\": \"050020\",\n",
    "  \"pubTime\": None,\n",
    "  \"currentPage\": \"0\",\n",
    "  \"pageSize\": 40,\n",
    "  \"key\": \"产品经理\",\n",
    "  \"suggestTag\": None,\n",
    "  \"workYearCode\": \"0\",\n",
    "  \"compId\": None,\n",
    "  \"compName\": None,\n",
    "  \"compTag\": None,\n",
    "  \"industry\": None,\n",
    "  \"salary\": None,\n",
    "  \"jobKind\": None,\n",
    "  \"compScale\": None,\n",
    "  \"compKind\": None,\n",
    "  \"compStage\": None,\n",
    "  \"eduLevel\": None\n",
    "}}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "c5493b88",
   "metadata": {},
   "outputs": [],
   "source": [
    "headers = {\n",
    "    'Accept': 'application/json, text/plain, */*',\n",
    "    'Accept-Encoding': 'gzip, deflate, br',\n",
    "    'Accept-Language': 'zh-CN,zh;q=0.9',\n",
    "    'Cache-Control': 'no-cache',\n",
    "    'Connection': 'keep-alive',\n",
    "    'Content-Length': '550',\n",
    "    'Content-Type': 'application/x-www-form-urlencoded',\n",
    "    'Cookie': 'inited_user=a0dcdca242be43aed8bc7937cd0de57c; __uuid=1681902847069.58; __gc_id=aff5183ad1a9412a972661b6b2a58509; _ga=GA1.1.1169277723.1681902907; __tlog=1682506318812.82%7C00000000%7C00000000%7Cs_00_003%7Cs_00_003; XSRF-TOKEN=9_P_0U7EQbqrvMPfELYU5Q; acw_tc=ac11000116825063428287871e00c826bf8783615dbcb9029f21cd4bbcc522; Hm_lvt_a2647413544f5a04f00da7eee0d5e200=1681902911,1682506343; UniqueKey=8f4be4ccd2ab2dcf7ecd4408bb1e9b04; liepin_login_valid=0; lt_auth=6ewJOXICyl%2BosXCPi2da7KtFiNyvVmnNpnpb00xT1dbpD6Lh4P%2FmQAOHqrQA%2FCoIqx1xdf4zMLb2N%2B3%2Bz3tP60Ua%2BFGkk564t%2FO%2B1HYKTuJkJ%2Fakh%2F2tmZnUQ5svwn4AmXk2pHpIykX1uy0yW5fT2WP1t5nX342my%2FP0iCyWqBg8; access_system=C; user_roles=0; need_bind_tel=false; new_user=true; c_flag=beb254435b47dbb6f7e52e7e380f3d5e; user_photo=5f8fa3a9dfb13a7dee343d4808u.png; user_name=%E9%99%88%E5%A4%A7%E5%BF%97; inited_user=a0dcdca242be43aed8bc7937cd0de57c; imClientId=b5e1273d5cb093f491df2b4878e9056b; imId=b5e1273d5cb093f44318ebb285ce453f; imClientId_0=b5e1273d5cb093f491df2b4878e9056b; imId_0=b5e1273d5cb093f44318ebb285ce453f; imApp_0=1; _ga_54YTJKWN86=GS1.1.1682506342.3.1.1682507002.0.0.0; __session_seq=10; __uv_seq=10; Hm_lpvt_a2647413544f5a04f00da7eee0d5e200=1682507002; fe_im_socketSequence_new_0=2_0_2; fe_im_opened_pages=; fe_im_connectJson_0=%7B%220_8f4be4ccd2ab2dcf7ecd4408bb1e9b04%22%3A%7B%22socketConnect%22%3A%222%22%2C%22connectDomain%22%3A%22liepin.com%22%7D%7D ',   \n",
    "    'Host':'api-c.liepin.com',\n",
    "    'Origin': 'https://www.liepin.com',\n",
    "    'Referer': 'https://www.liepin.com/',\n",
    "    'sec-ch-ua': '\"Chromium\";v=\"112\", \"Microsoft Edge\";v=\"112\", \"Not:A-Brand\";v=\"99\"',\n",
    "    'sec-ch-ua-mobile': '?0',\n",
    "    'sec-ch-ua-platform': '\"Windows\"',\n",
    "    'Sec-Fetch-Dest': 'empty',\n",
    "    'Sec-Fetch-Mode': 'cors',\n",
    "    'Sec-Fetch-Site': 'same-site',\n",
    "    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.58',\n",
    "    'X-Client-Type': 'web',\n",
    "    'X-Fscp-Bi-Stat': '{\"location\": \"https://www.liepin.com/zhaopin/?inputFrom=www_index&workYearCode=0&key=%E4%BA%A7%E5%93%81%E7%BB%8F%E7%90%86&scene=input&ckId=htihov8m2frxgy6ywo2wsg2gncnydzlb&dq=\"}',\n",
    "    'X-Fscp-Fe-Version': '',\n",
    "    'X-Fscp-Std-Info': '{\"client_id\": \"40108\"}',\n",
    "    'X-Fscp-Trace-Id': 'ca0f2044-5eea-413c-bc5a-1ebff017261f',\n",
    "    'X-Fscp-Version': '1.1',\n",
    "    'X-Requested-With': 'XMLHttpRequest',\n",
    "    'X-XSRF-TOKEN': '9_P_0U7EQbqrvMPfELYU5Q'\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "dc9a57ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(url,data=json.dumps(payload),headers=headers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "3f5c5cd9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 Edg/112.0.1722.58', 'Accept-Encoding': 'gzip, deflate, br', 'Accept': 'application/json, text/plain, */*', 'Connection': 'keep-alive', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Cache-Control': 'no-cache', 'Content-Length': '550', 'Content-Type': 'application/x-www-form-urlencoded', 'Cookie': 'inited_user=a0dcdca242be43aed8bc7937cd0de57c; __uuid=1681902847069.58; __gc_id=aff5183ad1a9412a972661b6b2a58509; _ga=GA1.1.1169277723.1681902907; __tlog=1682506318812.82%7C00000000%7C00000000%7Cs_00_003%7Cs_00_003; XSRF-TOKEN=9_P_0U7EQbqrvMPfELYU5Q; acw_tc=ac11000116825063428287871e00c826bf8783615dbcb9029f21cd4bbcc522; Hm_lvt_a2647413544f5a04f00da7eee0d5e200=1681902911,1682506343; UniqueKey=8f4be4ccd2ab2dcf7ecd4408bb1e9b04; liepin_login_valid=0; lt_auth=6ewJOXICyl%2BosXCPi2da7KtFiNyvVmnNpnpb00xT1dbpD6Lh4P%2FmQAOHqrQA%2FCoIqx1xdf4zMLb2N%2B3%2Bz3tP60Ua%2BFGkk564t%2FO%2B1HYKTuJkJ%2Fakh%2F2tmZnUQ5svwn4AmXk2pHpIykX1uy0yW5fT2WP1t5nX342my%2FP0iCyWqBg8; access_system=C; user_roles=0; need_bind_tel=false; new_user=true; c_flag=beb254435b47dbb6f7e52e7e380f3d5e; user_photo=5f8fa3a9dfb13a7dee343d4808u.png; user_name=%E9%99%88%E5%A4%A7%E5%BF%97; inited_user=a0dcdca242be43aed8bc7937cd0de57c; imClientId=b5e1273d5cb093f491df2b4878e9056b; imId=b5e1273d5cb093f44318ebb285ce453f; imClientId_0=b5e1273d5cb093f491df2b4878e9056b; imId_0=b5e1273d5cb093f44318ebb285ce453f; imApp_0=1; _ga_54YTJKWN86=GS1.1.1682506342.3.1.1682507002.0.0.0; __session_seq=10; __uv_seq=10; Hm_lpvt_a2647413544f5a04f00da7eee0d5e200=1682507002; fe_im_socketSequence_new_0=2_0_2; fe_im_opened_pages=; fe_im_connectJson_0=%7B%220_8f4be4ccd2ab2dcf7ecd4408bb1e9b04%22%3A%7B%22socketConnect%22%3A%222%22%2C%22connectDomain%22%3A%22liepin.com%22%7D%7D ', 'Host': 'api-c.liepin.com', 'Origin': 'https://www.liepin.com', 'Referer': 'https://www.liepin.com/', 'sec-ch-ua': '\"Chromium\";v=\"112\", \"Microsoft Edge\";v=\"112\", \"Not:A-Brand\";v=\"99\"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '\"Windows\"', 'Sec-Fetch-Dest': 'empty', 'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Site': 'same-site', 'X-Client-Type': 'web', 'X-Fscp-Bi-Stat': '{\"location\": \"https://www.liepin.com/zhaopin/?inputFrom=www_index&workYearCode=0&key=%E4%BA%A7%E5%93%81%E7%BB%8F%E7%90%86&scene=input&ckId=htihov8m2frxgy6ywo2wsg2gncnydzlb&dq=\"}', 'X-Fscp-Fe-Version': '', 'X-Fscp-Std-Info': '{\"client_id\": \"40108\"}', 'X-Fscp-Trace-Id': 'ca0f2044-5eea-413c-bc5a-1ebff017261f', 'X-Fscp-Version': '1.1', 'X-Requested-With': 'XMLHttpRequest', 'X-XSRF-TOKEN': '9_P_0U7EQbqrvMPfELYU5Q'}"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.request.headers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "e17434a6",
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(url)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "326d54f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.status_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "4a04d804",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'flag': 0, 'code': '-1400', 'msg': '出错了(400)!'}"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "cc870dda",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "17bbffdb",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "'data'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "Input \u001b[1;32mIn [11]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m pd\u001b[38;5;241m.\u001b[39mjson_normalize(\u001b[43mdata_liepin\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mdata\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mdata\u001b[39m\u001b[38;5;124m'\u001b[39m][\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mjobCardList\u001b[39m\u001b[38;5;124m'\u001b[39m])\n",
      "\u001b[1;31mKeyError\u001b[0m: 'data'"
     ]
    }
   ],
   "source": [
    "pd.json_normalize(data_liepin['data']['data']['jobCardList'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d70667af",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
